<template>
	<view class="content">
		<view class="vc-item" @click="uploadheader">
			<image :src="customerInfo.customer_headimg" class="header-img"></image>
			<view class="vc-item-content">
				<view class="choose-tips-text">修改头像</view>
				<image class="vc-item-arrow" src="../../../../static/images/right.png"></image>
			</view>
		</view>
		<view class="vc-item" @click="pushVc(10, '昵称', 'NickName')">
			<view>昵称</view>
			<view class="vc-item-content">
				<view>{{ customerInfo.customer_nickname }}</view>
				<image class="vc-item-arrow" src="../../../../static/images/right.png"></image>
			</view>
		</view>
		<view class="vc-item" @click="pushVc(10, '姓名', 'UserName')">
			<view>姓名</view>
			<view class="vc-item-content">
				<view>{{ customerInfo.customer_username }}</view>
				<image class="vc-item-arrow" src="../../../../static/images/right.png"></image>
			</view>
		</view>
		<view class="vc-item" @click="pushVc(20, '手机', 'Phone')">
			<view>手机</view>
			<view class="vc-item-content">
				<view>{{ customerInfo.customer_phone }}</view>
				<image class="vc-item-arrow" src="../../../../static/images/right.png"></image>
			</view>
		</view>
		<view class="vc-item" @click="pushVc(30, '性别', 'Gender')">
			<view>性别</view>
			<view class="vc-item-content">
				<view>{{ customerInfo.gender }}</view>
				<image class="vc-item-arrow" src="../../../../static/images/right.png"></image>
			</view>
		</view>
		<view class="vc-item" @click="pushVc(40, '生日', 'BirthDay')">
			<view>生日</view>
			<view class="vc-item-content">
				<view>{{ customerInfo.customer_birthday }}</view>
				<image class="vc-item-arrow" src="../../../../static/images/right.png"></image>
			</view>
		</view>
		<view class="vc-item" @click="pushVc(10, '身份证', 'Identity')">
			<view>身份证</view>
			<view class="vc-item-content">
				<view>{{ customerInfo.customer_identity }}</view>
				<image class="vc-item-arrow" src="../../../../static/images/right.png"></image>
			</view>
		</view>
		<view class="vc-item" @click="clickAddress">
			<view>收货地址</view>
			<view class="vc-item-content">
				<view class="choose-tips-text">维护收货地址</view>
				<image class="vc-item-arrow" src="../../../../static/images/right.png"></image>
			</view>
		</view>
		<view class="vc-item" @click="changeRechangePassWord" style="border-bottom: unset;">
			<view>交易密码</view>
			<view class="vc-item-content">
				<view class="choose-tips-text">修改密码</view>
				<image class="vc-item-arrow" src="../../../../static/images/right.png"></image>
			</view>
		</view>
	</view>
</template>

<script>
import { successToShow, errorToShow, null2str } from '@/config/common.js';
import { uploadImageToQiNiu } from '@/constant/home.js';
import { saveCustomerHeadimg } from '@/constant/customer.js';
import { getCustomerInfo} from '@/constant/customer.js';
export default {
	data() {
		return {
			customerId: '',
			customerInfo: {
				customer_headimg: '',
				customer_nickname: '',
				customer_username: '',
				customer_phone: '',
				customer_birthday: '',
				customer_identity: '',
				customer_gender: '',
				gender: ''
			}
		};
	},
	onShow() {
		this.getUserInfo();
	},
	methods: {
		uploadheader() {
			let that = this;
			uploadImageToQiNiu(1, 8, res => {
				saveCustomerHeadimg({ id: that.customerId, url: res }).then(function() {
					successToShow('修改成功');
					that.customerInfo.customer_headimg = res;
					let result = uni.getStorageSync('customerInfo');
					result.HeadImg = res;
					uni.setStorageSync('customerInfo', result);
				});
			});
		},
		 getUserInfo() {
			this.customerId = uni.getStorageSync('customerId');
			
			let result = uni.getStorageSync('customerInfo');
			result = null2str(result);
			console.log(result,'result=---')
			this.customerInfo.customer_headimg = result.headImg;
			this.customerInfo.customer_nickname = result.nickName;
			this.customerInfo.customer_username = result.userName;
			this.customerInfo.customer_phone = result.phone;
			this.customerInfo.customer_birthday = result.birthDay.length > 0 ? result.birthDay.substr(0, 10) : '';
			this.customerInfo.customer_gender = result.gender==0;
			this.customerInfo.gender = this.customerInfo.customer_gender == 1 || this.customerInfo.customer_gender == '男' ? '男' : '女';
			this.customerInfo.customer_identity = result.identity;
		},
		clickAddress() {
			uni.navigateTo({
				url: '../../myaddress/index'
			});
		},
		changeRechangePassWord() {
			uni.navigateTo({
				url: '../../setting/index'
			});
		},
		pushVc(_type, _title, _key) {
			let _value = '';
			switch (_key) {
				case 'NickName':
					_value = this.customerInfo.customer_nickname;
					break;
				case 'UserName':
					_value = this.customerInfo.customer_username;
					break;
				case 'Phone':
					_value = this.customerInfo.customer_phone;
					break;
				case 'Identity':
					_value = this.customerInfo.customer_identity;
					break;
				case 'BirthDay':
					_value = this.customerInfo.customer_birthday;
					break;
				case 'Gender':
					_value = this.customerInfo.customer_gender;
					break;
			}
			uni.navigateTo({
				url: '../edit/edit?type=' + _type + '&title=' + _title + '&key=' + _key + '&values=' + _value
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.content {
	height: 100vh;
	padding: 30rpx;
	padding-top: unset;
}

.header-img {
	width: 96rpx;
	height: 96rpx;
	border-radius: 50%;
}

.vc-item {
	padding: 30rpx 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	border-bottom: 2rpx solid $main-line-color-gray-F5;
	&-content {
		display: flex;
		align-items: center;
		justify-content: flex-end;
		color: $main-text-color-gray-33;
		font-size: $main-text-size-32;
	}
	&-arrow {
		width: 18rpx;
		height: 32rpx;
		margin-left: 10rpx;
	}
}

.choose-tips-text {
	color: $main-text-color-grey;
	font-size: $main-text-size-32;
}
</style>
